package com.zjf.bbs.tag;

import java.io.IOException;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import com.zjf.bbs.entity.Plat;

public class PlatGPSTag extends SimpleTagSupport {
	private Plat plat;
	
	public Plat getPlat() {
		return plat;
	}

	public void setPlat(Plat plat) {
		this.plat = plat;
	}

	@Override
	public void doTag() throws JspException, IOException {
		try {
			JspContext jc = getJspContext();
			PageContext pc = (PageContext) jc;
			String contextPath = pc.getServletContext().getContextPath();
			JspWriter out = pc.getOut();
			StringBuilder outStr = new StringBuilder();
			String content = "<a href='"+contextPath+"/postList.do?pid="+plat.getId()+"'>"+plat.getName()+"</a>";
//			outStr.append(content, 0,content.length() );
			outStr.insert(0,content);
			while(plat.getParent()!=null){
				outStr.insert(0,"-");
				content = "<a href='"+contextPath+"/postList.do?pid="+plat.getParent().getId()+"'>"+plat.getParent().getName()+"</a>";
				outStr.insert(0,content);
				plat = plat.getParent();
			}
			out.print(outStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
